What is Python Virtual Environment?
331
21-Oct-2025
Updated on 21-Oct-2025
Anubhav Kumar
21-Oct-2025Here’s a quick guide to understanding and using it:
Why Use a Virtual Environment?
Without a venv:
With a venv:
How to Create and Use a Virtual Environment
1. Check Python Installation
2. Create a Virtual Environment
myenvcontaining a private Python setup.myenvto any name you like.3. Activate the Virtual Environment
Windows:
macOS/Linux:
After activation, your terminal prompt will show:
4. Install Packages Inside the venv
Check installed packages:
5. Freeze Dependencies (optional but important)
Save all installed packages to a file:
Later, you can recreate the same environment with:
6. Deactivate the Virtual Environment
Alternative Tools
venvvirtualenvpipenvpip+venv+ dependency lockingpoetry